//
//  CrazyChatCustomGoodsCell.m
//  webSocket
//
//  Created by 马军凯 on 2019/2/18.
//  Copyright © 2019年 ZH. All rights reserved.
//

#import "CrazyChatCustomGoodsCell.h"

@interface CrazyChatCustomGoodsCell ()

@property (nonatomic, strong) UIImageView *customHeadImageView; //头像
@property (nonatomic, strong) UIView *customGoodsBackView; //背景
@property (nonatomic, strong) UIImageView *customGoodsBackImageView; //背景图片
@property (nonatomic, strong) UIImageView *customGoodsImageView; //图片
@property (nonatomic, strong) UILabel *customGoodsTitleLabel; //标题
@property (nonatomic, strong) UILabel *customGoodsPriceLabel; //价格

@end


@implementation CrazyChatCustomGoodsCell

- (void)awakeFromNib {
    [super awakeFromNib];
    // Initialization code
}



+ (instancetype)cellWithTableView:(UITableView *)tableView {
    static NSString *identifier = CrazyChatCustomGoodsIdentifier;
    
    //缓存中取
    CrazyChatCustomGoodsCell *cell = [tableView dequeueReusableCellWithIdentifier:identifier];
    
    //创建
    if (!cell) {
        cell = [[CrazyChatCustomGoodsCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:identifier];
    }
    
    
    return cell;
}


- (instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier {
    if (self = [super initWithStyle:style reuseIdentifier:reuseIdentifier]) {
        self.selectionStyle = UITableViewCellSelectionStyleNone;
        self.backgroundColor = [UIColor clearColor];
        //头像
        self.customHeadImageView = [[UIImageView alloc] init];
        self.customHeadImageView.frame = CGRectMake(15, 10, 40, 40);
        [self.contentView addSubview:self.customHeadImageView];
        //背景
        self.customGoodsBackView = [[UIView alloc] init];
        self.customGoodsBackView.frame = CGRectMake(60, 10, CRAZY_SCREEN_WIDTH - 120, 100);
        [self.contentView addSubview:self.customGoodsBackView];
        //背景图片
        self.customGoodsBackImageView = [[UIImageView alloc] init];
        self.customGoodsBackImageView.frame = self.customGoodsBackView.bounds;
        self.customGoodsBackImageView.image = [[UIImage imageNamed:@"Crazy_chat_leftPic@2x.png"] resizableImageWithCapInsets:UIEdgeInsetsMake(23, 15, 7, 15) resizingMode:UIImageResizingModeStretch];
        [self.customGoodsBackView addSubview:self.customGoodsBackImageView];
        //图片
        self.customGoodsImageView = [[UIImageView alloc] init];
        self.customGoodsImageView.frame = CGRectMake(12, 10, 80, 80);
        [self.customGoodsBackView addSubview:self.customGoodsImageView];
        //标题
        self.customGoodsTitleLabel = [[UILabel alloc] init];
        self.customGoodsTitleLabel.numberOfLines = 2;
        self.customGoodsTitleLabel.font = [UIFont systemFontOfSize:14];
        self.customGoodsTitleLabel.textColor = CRAZY_RGBR(33);
        [self.customGoodsBackView addSubview:self.customGoodsTitleLabel];
        //价格
        self.customGoodsPriceLabel = [[UILabel alloc] init];
        self.customGoodsPriceLabel.textColor = [UIColor redColor];
        self.customGoodsPriceLabel.font = [UIFont systemFontOfSize:14];
        [self.customGoodsBackView addSubview:self.customGoodsPriceLabel];
        [self.customGoodsPriceLabel mas_makeConstraints:^(MASConstraintMaker *make) {
            make.left.mas_equalTo(97);
            make.bottom.mas_equalTo(-10);
            make.width.mas_equalTo(self.customGoodsBackView.width - 105);
        }];
        //查看
        self.customGoodsCheckBtn = [UIButton buttonWithType:UIButtonTypeCustom];
        self.customGoodsCheckBtn.frame = self.customGoodsBackView.bounds;
        [self.customGoodsBackView addSubview:self.customGoodsCheckBtn];
    }
    return self;
}


//赋值
- (void)setCellValueWithHeadURL:(NSString *)headURL picURL:(NSString *)picURL title:(NSString *)title price:(NSString *)price {
    //头像
    [self.customHeadImageView sd_setImageWithURL:[NSURL URLWithString:headURL] placeholderImage:CRAZY_DEFAULT_HEADIMAGE];
    //图片
    [self.customGoodsImageView sd_setImageWithURL:[NSURL URLWithString:picURL] placeholderImage:CRAZY_DEFAULT_LOADIMAGE];
    //标题
    self.customGoodsTitleLabel.text = title;
    CGSize maxSize = CGSizeMake(self.customGoodsBackView.width - 90, 40);
    CGSize size = [self.customGoodsTitleLabel sizeThatFits:maxSize];
    self.customGoodsTitleLabel.frame = CGRectMake(97, 10, self.customGoodsBackView.width - 105, size.height);
    //价格
    self.customGoodsPriceLabel.text = [NSString stringWithFormat:@"%@%@", @"¥", price];
}












- (void)setSelected:(BOOL)selected animated:(BOOL)animated {
    [super setSelected:selected animated:animated];

    // Configure the view for the selected state
}

@end
